<?php
class core_security extends object {

public $username="";
public $passwd="";

function checkuser_data_validate() {
	$loc = new loc;
	$out="";	
	if ($this->username == "") {
		$out=$out."<br>".$loc->login_username_miss; 
		}	
	if ($this->passwd == "") {
		$out=$out."<br>".$loc->login_password_miss; 
		}
	return $out;
	}

function checkuser_validate() {
	$loc=new loc;	
	$out="";
	$validate=$this->checkuser_data_validate();
	if ($validate == "") {
		$passw=sha1($this->passwd);
		$result=mysql_query("select passwd,disabled from users where login = '".mysql_real_escape_string($this->username)."'");
		if ($result != "") {
			$row=mysql_fetch_array($result);
			if ($row['disabled'] == 1) {
					$out=$out."<br>".$loc->login_disabled; 	
					}
			if ($row['passwd'] != $passw) {
				
				$out=$out."<br>".$loc->login_failed; 				
				}			
			} else {
			$out=$out."<br>".$loc->login_failed; 
			}		
		}else {
			$out=$out."<br>".$loc->login_failed; 
			}
	return $out;
	}

function setlogin() {
	$validatelogin=$this->checkuser_validate();
	if ($validatelogin=="") {
		//session_start();
		$_SESSION['logged']="OK";
		$result=mysql_query("select * from users where login = '".mysql_real_escape_string($this->username)."'");
		$row=mysql_fetch_array($result);
		$_SESSION['login']=$this->username;
		$_SESSION['uid']=$row['id'];	
		$_SESSION['date']=date('m/d/Y');
		$_SESSION['date2']=date('d:m:Y');
		$_SESSION['role']=$row['role'];
		$_SESSION['view']="main";
		$_SESSION['username']=$row['name'];
		}	
	}
	
function unsetlogin() {
	if (isset($_SESSION['logged'])) {
	if ($_SESSION['logged'] == "OK") {
		session_unset();
		session_destroy();		
		}	
		}
	}
function checklogin() {
	if (isset($_SESSION['logged'])) {
	if ($_SESSION['logged'] == "OK") {
		return "OK";		
		}
	}
	}
	
}
?>
